const app = getApp();

const URL = app.globalData.URL;

let navList = [
  {
    name: '全部订单',
    thumb:
      'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*Y8BATYqMN78AAAAAAAAAAABkARQnAQ',
    onClick: () => {
      if(app.globalData.smrz){
        my.navigateTo({
          url: '/pages/order/order',
        })
      }else{
        my.alert({ title: "请实名认证！" });
        return;
      }
    }
  },
  {
    name: '手机号',
    value:app.globalData.mobile,
    thumb:
    'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*Y8BATYqMN78AAAAAAAAAAABkARQnAQ',
    onClick: () =>
      {my.alert({title:"手机号",content:app.globalData.mobile})},
  },
  {
    name: '实名认证',
    value:app.globalData.smrz,
    thumb:
    'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*Y8BATYqMN78AAAAAAAAAAABkARQnAQ',
    onClick: () =>
      my.navigateTo({
        url: '/pages/mine/components/smrz/smrz',
      }),
  },
  {
    name: '授权',
    value: '',
    thumb:
    'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*Y8BATYqMN78AAAAAAAAAAABkARQnAQ',
    onClick: () =>
      my.navigateTo({
        url: '/pages/mine/components/sq/sq',
      }),
  },
  // {
  //   name: '优惠券',
  //   thumb:
  //     'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*9RqXQaxLeCEAAAAAAAAAAABkARQnAQ',
  //   onClick: () =>
  //   my.alert({content:"敬请期待！"}),
  // },
  // {
  //   name: '投诉咨询',
  //   thumb:
  //     'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*9RqXQaxLeCEAAAAAAAAAAABkARQnAQ',
  //   onClick: () =>
  //   my.alert({content:"敬请期待！"}),
  // },
  // {
  //   name: '意见反馈',
  //   thumb:
  //     'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*9RqXQaxLeCEAAAAAAAAAAABkARQnAQ',
  //   onClick: () =>
  //   my.alert({content:"敬请期待！"}),
  // },
  
  // {
  //   name: '专属客服',
  //   thumb:
  //     'https://gw.alipayobjects.com/mdn/rms_107da2/afts/img/A*-Lp1TZDggnoAAAAAAAAAAABkARQnAQ',
  //   onClick: () => {
  //     my.alert({content:"敬请期待！"})
  //   },
  // },
];

Page({
  data: {
    nickname: app.globalData.nickName, //用户昵称
    avatar: app.globalData.avatar, //用户头像
    mobile:app.globalData.mobile,
    isLogin: false, //是否登录
    smrz:app.globalData.smrz,
    currentUser: {
      name: app.globalData.nickName,
      member: '',
    },
    entries: [
      {
        title: '待付款',
        cover:
          '/image/order/01.png',
          onClick: () =>
        my.alert({content:"敬请期待！"}),
      },
      {
        title: '待收货',
        cover:
          '/image/order/02.png',
      },

      {
        title: '租赁中',
        cover:
          '/image/order/03.png',
      },

      {
        title: '逾期中',
        cover:
          '/image/order/04.png',
      },

      {
        title: '已完结',
        cover:
          '/image/order/05.png',
      },
    ],
    navList: navList,
  },
  onLoad(){
    my.httpRequest({
      url: `${URL}/app-api/chl/app/getAlipayUserSeal`,
      data: {
        phone:app.globalData.mobile,
      },
      headers:{"tenant-id":"1",
      'content-type': 'application/x-www-form-urlencoded'},
      success: (res) => {
        if (res.data.data) {
          console.log(res.data.data);
          console.log("1-------"+app.globalData.smrz);

          var smrz = res.data.data.realNameStatus;
          if(smrz=="true"){
            this.setData({smrz:true});
            app.globalData.smrz = true;
            console.log("2-------"+app.globalData.smrz);

            this.setData(
              {
                phone:app.globalData.mobile,
                name:res.data.data.userName,
                idCard:res.data.data.idCard,
              }
            );

          }else{
            this.setData({smrz:false});
            app.globalData.smrz = false;
          }
        }else{
          this.setData({smrz:false});
          app.globalData.smrz = false;
        }
      },
      fail: (err) => {
        my.alert({'content':'认证失败'});
        this.setData({smrz:false});
        app.globalData.smrz = false;
      }
    });
    
  },
  onShow(){
    this.setData(
      {
      nickname: app.globalData.nickName,
      avatar: app.globalData.avatar,
      isLogin: app.globalData.isLogin, //是否登录
      smrz:app.globalData.smrz
     }
    );
    //my.alert({content:app.globalData});

    navList[1].value = app.globalData.mobile;

    //my.alert({content:navList[1]});

    this.setData(
      {navList: navList}
    );

    if(app.globalData.isLogin) {
    }else {
      my.navigateTo({
        url: '/pages/mine/components/sq/sq',
      })
    }

  },
  onListClick({ target: { dataset } }) {
    const { onClick } = this.data.navList[dataset.index];
    if (onClick) {
      onClick();
    }
  },
  onOrderClick() {
    my.navigateTo({
      url: '/pages/my-name/my-name',
    })

  },
  onSqHandler(){
    my.navigateTo({
      url: '/pages/mine/components/sq/sq',
    })

  }
});
